package com.yy.controller.mapper;

import com.github.pagehelper.Page;
import com.yy.dto.CategoryQueryDTO;
import com.yy.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 分类条件分页查询
     * @param categoryQueryDTO
     * @return
     */
    public Page<Category> pageList(CategoryQueryDTO categoryQueryDTO);

    /**
     * 根据id删除分类
     * @param id
     */
    @Delete("delete from category  where  id=#{id}")
    void deleteById(Long id);

    /**
     * 添加分类
     * @param category
     */
    @Insert("insert into category (id, type, name,status, sort, create_time" +
            ", update_time, create_user, update_user) values" +
            " (#{id},#{type},#{name},#{status},#{sort},#{createTime},#{updateTime}" +
            ",#{createUser},#{updateUser})")
    void add(Category category);

    /**
     * 根据id修改分类
     * @param category
     */
    @Update("update category set type=#{type},name=#{name}," +
            "status=#{status},sort=#{sort}," +
            "update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void update(Category category);

    /**
     * 修改分类状态
     * @param category
     */
    @Update("update category set status=#{status}" +
            ",update_time=#{updateTime}" +
            ",update_user=#{updateUser} where id=#{id}")
    void editeStatus(Category category);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @Select("select * from category where  type=#{type}")
    List<Category> listByType(Integer type);

    /**
     * 获取启用分类
     * @return
     */
    @Select("select * from  category where status=1")
    List<Category> listByStatus();
}
